﻿#!/usr/bin/env python3

import sqlite3

def main():
    '''sqlite3 -  
几个步骤: 1.创建connection. 2.取得cursor. 3.execute SQL. 4.commit. 5.最后close    '''
    print(main.__doc__)
    print("="*30)

    conn = sqlite3.connect(':memory:')
    c = conn.cursor()
    c.execute('''CREATE TABLE COMPANY
        (ID INT PRIMARY KEY     NOT NULL,
        NAME           TEXT    NOT NULL,
        AGE            INT     NOT NULL);''')

    c.execute("INSERT INTO COMPANY VALUES (1, 'Paul', 32)")
    c.execute("INSERT INTO COMPANY VALUES (2, 'Allen', 25)")
    c.execute("INSERT INTO COMPANY VALUES (3, 'Teddy', 23)")
    c.execute("INSERT INTO COMPANY VALUES (4, 'Mark', 25)")
    
    cursor = c.execute("SELECT ID, NAME, AGE  from COMPANY")
    for row in cursor:
        print("ID = {0}, name= {1}, age={2}".format(row[0], row[1], row[2]))

    conn.commit()

    conn.close()

if __name__=='__main__':
    main()
